/*
* pps_bom
*/
package com.pitop.material.service;

import com.pitop.core.entity.Page;
import com.pitop.core.exceptions.BaseException;
import com.pitop.core.exceptions.MaterialLogException;
import com.pitop.material.api.MaterialLogFeignApi;
import com.pitop.material.entity.MaterialLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 物料日志
 *
 * @author berton
 */
@Service("materialLogSVImpl")
@Slf4j
public class MaterialLogSVImpl {

    @Autowired
    private MaterialLogFeignApi materialLogFeignApi;

    /**
     * 加载一个对象MaterialLog
     *
     * @param id
     * @return MaterialLog
     */
    public MaterialLog load(Long id) {
        if (id == null) {
            throw new MaterialLogException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return materialLogFeignApi.load(id);
    }

    /**
     * 加载一个对象MaterialLog 通过id,(将查询关联数据)
     *
     * @param id
     * @return MaterialLog
     */
    public MaterialLog loadById(Long id) {
        if (id == null) {
            throw new MaterialLogException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return materialLogFeignApi.loadById(id);
    }


    /**
     * 删除对象MaterialLog
     *
     * @param id
     */

    public void delete(Long id) {
        if (id == null) {
            throw new MaterialLogException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        materialLogFeignApi.delete(id);
    }

    /**
     * 查询MaterialLog分页
     *
     * @param materialLog 对象
     * @param curPage     当前页
     * @param pageSize    分页条数
     * @return List<MaterialLog>
     */
    public List<MaterialLog> list(MaterialLog materialLog, int curPage, int pageSize) {
        return materialLogFeignApi.list(materialLog, curPage, pageSize);
    }

    /**
     * 查询MaterialLog分页
     *
     * @param id
     * @param curPage  当前页
     * @param pageSize 分页条数
     * @return List<MaterialLog>
     */
    public List<MaterialLog> list(Long id, int curPage, int pageSize) {
        if (curPage < 0) {
            curPage = 1;
        }

        if (pageSize < 0) {
            pageSize = Page.limit;
        }

        MaterialLog materialLog = new MaterialLog();
        materialLog.setId(id);

        return materialLogFeignApi.list(materialLog, curPage, pageSize);
    }

    public int count(Long id) {
        return materialLogFeignApi.count(id);
    }

    public int count(MaterialLog materialLog) {
        return materialLogFeignApi.count(materialLog);
    }

    /**
     * 保存
     *
     * @param materialLog 实体
     * @throws BaseException
     */
    public void save(MaterialLog materialLog) {
        if (materialLog == null) {
            throw new MaterialLogException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        materialLogFeignApi.build(materialLog);
    }

    /**
     * 更新
     *
     * @param materialLog 实体
     * @throws BaseException
     */
    public void modify(MaterialLog materialLog) {
        if (materialLog == null) {
            throw new MaterialLogException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        materialLogFeignApi.modify(materialLog);
    }
}
